﻿using System.Collections.Generic;
using System.Net;
using System.Threading.Tasks;
using JTTD.Common.Attribute;
using JTTD.Common.Enum;
using JTTD.Common.Helper;
using JTTD.Domain.Dtos;
using JTTD.Domain.Dtos.System.Request;
using JTTD.Domain.Dtos.System.Response;
using JTTD.Domain.IService;
using JTTD.Extensions;
using Microsoft.AspNetCore.Mvc;

namespace JTTD.Controllers
{
    /// <summary>
    /// 系统配置
    /// </summary>
    [Route("api/systems")]
    [ApiController]
    public class SystemController : BaseController
    {
        private readonly IConfigService  _configService;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="configService"></param>
        public SystemController(IConfigService configService)
        {
            _configService = configService;
        }

        /// <summary>
        /// 设置配置(后台管理员)
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("config")]
        [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(ApiResult<bool>))]
        [UserRoot(UserType = Common.Enum.UserTypeEnum.Admin)]
        public async Task<IActionResult> SetConfig([FromBody]SetConfigRequestDto dto)
        {
            var result = await _configService.SetConfig(dto);
            return Ok(result);
        }

        /// <summary>
        ///获取所有配置（后台管理员）
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("")]
        [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(ApiResult<List<ConfigInfoResponseDto>>))]
        [UserRoot(UserType = Common.Enum.UserTypeEnum.Admin)]
        public async Task<IActionResult> GetCofigInfoList()
        {
            var result = await _configService.GetCofigInfoList();
            return Ok(result);
        }

        /// <summary>
        ///获取当个配置（微信公众号）
        /// </summary>
        /// <param name="configType"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("{configType}")]
        [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(ApiResult<ConfigInfoResponseDto>))]
        [UserRoot(UserType=UserTypeEnum.Ordinary)]
        public async Task<IActionResult> GetConfig([FromRoute]ConfigTypeEnum configType)
        {
            var result = await _configService.GetConfig(configType);
            return Ok(result);
        }

        /// <summary>
        /// 根据登录账号角色获取导航栏菜单
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("menus")]
        [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(ApiResult<List<LoadXmlResult<MenuInfoResponseDto>>>))]
        public async Task<IActionResult> GetMenuList()
        {
            var result = await _configService.GetMenuList((UserTypeEnum)UserType);
            return Ok(result);
        }
      

    }
}